Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug #324 - prevent unaligned load access #329

Merged
merged 1 commit into from
Jan 10, 2024

Conversation

1bsyl
Copy link
Contributor

@1bsyl 1bsyl commented Jan 9, 2024

Fixed bug #324 - prevent unaligned load access
use memcpy so we can expect the compiler to optimize when possible

use memcpy so we can expect the compiler to optimize when possible
@slouken
Copy link
Collaborator

slouken commented Jan 9, 2024

Can you check the disassembly and verify that this is actually turned into optimized instructions?

@1bsyl
Copy link
Contributor Author

1bsyl commented Jan 9, 2024

yes,
using memcpy and -O2 gives the same output (well almost, but optimized)
(.. so I don't know how ubsan achieves to ignore the unaligned load, since it's the same code ...looking at the source maybe..)

If I use SDL_memcopy, it adds SDL_memcpy calls.

@matoro
Copy link

matoro commented Jan 10, 2024

Tested and this indeed does fix the issue. Also, @slouken here's proof this compiles to identical assembly on x86: https://godbolt.org/z/aG1qnvn4o Note there are only differences at -O0, it gets optimized correctly at -O1 or higher.

@slouken slouken merged commit d2e6ded into libsdl-org:main Jan 10, 2024
5 checks passed
@slouken
Copy link
Collaborator

slouken commented Jan 10, 2024

Merged to main and SDL2, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants